 package cn.swust.classdemo;

import static org.junit.Assert.*;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.verify;

/**
 * 赋值测试
 */
public class MockDemoTest01 {
	private double DELTA = 1e-15;

	@Before
	public void setUp() throws Exception {
		 
	}

	@Test
	public void testAdd_mock() {
		AddTwoFun mockTwo = mock(AddTwoFun.class);
		MockDemo testObj = new MockDemo();
		testObj.addTwo = mockTwo; 
		
		int a = 50;
		int b = 60;
		int c = 30;
		int exp = 140;
		Mockito.when(mockTwo.add(70, 60))
		.thenReturn(110);
		int act = testObj.add(a, b, c);
		Assert.assertEquals(exp, act);
		//Assert.assertEquals(0.11, 0.05, DELTA);
		//Mockito.verify(mockTwo).add(50, 60);
	}
	
	@Test
	public void testAdd() {
		MockDemo testObj = new MockDemo();
		int a = 50;
		int b = 60;
		int c = 30;
		int exp = 140;
		int act = testObj.add(a, b, c);
		Assert.assertEquals(exp, act);
	} 
}
